package cn.usian.controller;

import cn.usian.feign.client.UserClient;
import cn.usian.feign.pojo.User;
import cn.usian.service.OrderServcie;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("backend")
public class OrderController {
    @Autowired
    private OrderServcie orderServcie;
    @Autowired
    private UserClient userClient;

    @GetMapping("findById")
    public User findById(@RequestParam("id") Long id){
        User user = userClient.findById(id);
        return user;
    }

    @GetMapping("findPage")
    public Page<User> findPage(@RequestParam(required = true,defaultValue = "1")Integer pageIndex, @RequestParam("name") String name){
        Page<User> page = userClient.findPage(pageIndex, name);
        return page;
    }

    @PostMapping("add")
    public String add(@RequestBody User user){
       return userClient.addUser(user);
    }

    @PostMapping("edit")
    public String edit(@RequestBody User user){
       return userClient.edit(user);
    }

    @GetMapping("del")
    public String del(@RequestParam("id") Long id){
       return userClient.del(id);
    }
}
